import 'package:dmz/base/pageWidget/base_stateful_widget.dart';
import 'package:dmz/base/widget/defult_text_field.dart';
import 'package:dmz/base/widget/defult_widget.dart';
import 'package:dmz/business/home/controller/map_location_controller.dart';
import 'package:dmz/business/home/model/moto_model.dart';
import 'package:dmz/business/home/model/moto_search.dart';
import 'package:dmz/business/home/model/serve_point.dart';
import 'package:dmz/business/home/widgets/shanre_details_widgets.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

class MapWidgets {
  static fenceTopeWidget(String address, int selectData, bool open,
      Function() click, Function() actuon) {
    itme(String title,
        {String? content, bool haveBtn = false, int? otherData}) {
      return Column(mainAxisSize: MainAxisSize.min, children: [
        Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
                Row(
                    mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                    children: [
                      DefaultText(title, 40.sp,
                          textColor: const Color(0xFFF9F9F9),
                          fontWeight: FontWeight.w700),
                    ]),
                if (content != null)
                  DefaultText(content, 28.sp,
                      textColor: const Color(0xFFF9F9F9))
              ]),
              if (haveBtn)
                Image.asset(
                        'assets/images/home/set/btn_${open ? 'open' : 'close'}.png',
                        width: 110.sp,
                        height: 66.sp)
                    .addGestureDetector(() => actuon()),
              if (otherData != null)
                Row(children: [
                  DefaultText('$otherData${'km'}', 32.sp,
                          textColor: const Color(0xFFF9F9F9))
                      .marginOnly(right: 20.sp),
                  Image.asset('assets/images/home/set/right_icon.png',
                      width: 18.sp, height: 36.sp)
                ])
            ]),
        Container(height: 2.sp, color: const Color(0xFFD8D8D8))
            .marginOnly(top: 42.sp)
      ]).paddingOnly(top: 48.sp, left: 32.sp, right: 32.sp);
    }

    return Container(
        color: const Color(0xFF434650),
        child: Column(mainAxisSize: MainAxisSize.min, children: [
          itme('围栏开关'.tr, content: '卡片尾打开后获取车辆位置超过围栏设置范围会触'.tr, haveBtn: true),
          itme('围栏中心'.tr, content: address),
          itme('围栏范围'.tr, otherData: selectData).addGestureDetector(click)
        ]));
  }

  static Widget locationBottomWidget(
      MotoModel data, String? address, Function openMap) {
    return Container(
        padding: EdgeInsets.only(left: 32.sp, right: 10.sp),
        height: 384.sp,
        decoration: BoxDecoration(
          borderRadius: BorderRadius.only(
            topLeft: Radius.circular(60.sp),
            topRight: Radius.circular(60.sp),
          ),
          color: const Color(0xFF434650),
        ),
        child: Row(children: [
          Container(
                  color: const Color(0xFFA0A1A6),
                  child: DefaultNetWorkImage(data.photo ?? '',
                      width: 112.sp, height: 112.sp))
              .didClipRRectAll(112.sp)
              .marginOnly(right: 32.sp),
          Expanded(
              child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  mainAxisSize: MainAxisSize.min,
                  children: [
                DefaultText(data.name ?? '', 48.sp,
                    textColor: const Color(0xFFF9F9F9),
                    fontWeight: FontWeight.w700),
                DefaultText(address ?? '', 28.sp,
                    textColor: const Color(0xFF999999))
              ])),
          Image.asset('assets/images/home/main/turn_icon.png',
                  width: 128.sp, height: 128.sp)
              .addGestureDetector(() => openMap())
        ]));
  }

  static seleMapAppWidget(Function(int) select) {
    item(type) {
      return Column(mainAxisSize: MainAxisSize.min, children: [
        DefaultText(
          type == 0 ? '高德地图'.tr : '百度地图'.tr,
          40.sp,
          fontWeight: FontWeight.w700,
          textColor: const Color(0xFFF9F9F9),
        ).marginOnly(top: 48.sp, bottom: 48.sp),
        Container(
          height: 2.sp,
          color: const Color(0xFFD8D8D8),
        )
      ])
          .marginOnly(left: 32.sp, right: 32.sp)
          .addGestureDetector(() => select(type));
    }

    return ShareDetailsWidgets.widowBackWidget(
        '选择导航软件'.tr,
        Column(mainAxisSize: MainAxisSize.min, children: [item(0), item(1)])
            .marginOnly(bottom: 162.sp));
  }

  static Widget searchWidget() {
    searchItem(SearchResult data, Function click) {
      return Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
        Container(
            padding: EdgeInsets.only(
                top: 20.sp, bottom: 20.sp, left: 32.sp, right: 32.sp),
            color: Colors.black,
            child:
                Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
              DefaultText(data.name, 32.sp, textColor: Colors.white),
              DefaultText(data.address, 28.sp, textColor: Colors.white)
            ])),
        Container(height: 2.sp, color: const Color(0xFFF5F5F5))
            .marginOnly(left: 32.sp, right: 32.sp)
      ]).addGestureDetector(() => click());
    }

    return GetBuilder<MotoLocationController>(
        id: 'searchList',
        builder: (controller) {
          return Container(
              color: Colors.black,
              child: Column(mainAxisSize: MainAxisSize.min, children: [
                Container(
                    padding: EdgeInsets.only(
                        left: 32.sp, right: 16.sp, bottom: 20.sp),
                    color: Colors.black,
                    child: Row(
                        mainAxisAlignment: MainAxisAlignment.spaceAround,
                        children: [
                          Container(
                              padding:
                                  EdgeInsets.only(left: 40.sp, right: 40.sp),
                              width: 648.sp,
                              color: const Color(0xFF313131),
                              height: 120.sp,
                              child: Row(children: [
                                Expanded(
                                    child: DefultTextField(32.sp,
                                        controlle: controller.textController,
                                        hintText: '请输入目的地'.tr,
                                        onChanged: (text) =>
                                            controller.searchAddress(text))),
                                Image.asset(
                                        'assets/images/login/input_clean.png',
                                        width: 48.sp,
                                        height: 48.sp)
                                    .addGestureDetector(
                                        () => controller.turnSelect())
                                    .marginOnly(left: 10.sp)
                              ])).didClipRRectAll(120.sp),
                          Image.asset('assets/images/home/main/turn_icon.png',
                                  width: 128.sp, height: 128.sp)
                              .addGestureDetector(() => controller.seleMapApp())
                        ])),
                if (controller.searchResults.isNotEmpty)
                  Container(
                      constraints: BoxConstraints(maxHeight: 1000.sp),
                      child: ListView.builder(
                          shrinkWrap: true,
                          itemCount: controller.searchResults.length,
                          itemBuilder: (context, index) {
                            var data = controller.searchResults[index];
                            return searchItem(
                                data, () => controller.resultClick(data));
                          }))
              ]));
        });
  }

  static Widget servePointWidget(ServePoint data, Function callback) {
    item(type, content) {
      return Row(children: [
        Image.asset(
            'assets/images/home/main/${type == 0 ? 'phone' : 'address'}_icon.png',
            width: 76.sp,
            height: 76.sp),
        DefaultText(content ?? '', 32.sp, textColor: const Color(0xFFF9F9F9))
            .marginOnly(left: 32.sp)
      ]);
    }

    return Container(
        padding: EdgeInsets.only(left: 32.sp, top: 48.sp, right: 32.sp),
        decoration: BoxDecoration(
          borderRadius: BorderRadius.only(
            topLeft: Radius.circular(60.sp),
            topRight: Radius.circular(60.sp),
          ),
          color: const Color(0xFF434650),
        ),
        child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            mainAxisSize: MainAxisSize.min,
            children: [
              Row(mainAxisAlignment: MainAxisAlignment.start, children: [
                Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
                  DefaultText('网点信息'.tr, 48.sp,
                          textColor: const Color(0xFFF9F9F9),
                          fontWeight: FontWeight.w700)
                      .marginOnly(bottom: 48.sp),
                  DefaultText('${data.name}', 40.sp,
                      textColor: const Color(0xFF23C565))
                ]),
                const Expanded(child: SizedBox()),
                Image.asset('assets/images/home/main/turn_icon.png',
                        width: 128.sp, height: 128.sp)
                    .addGestureDetector(() => callback())
              ]).marginOnly(bottom: 48.sp),
              item(0, data.phone).marginOnly(bottom: 48.sp),
              item(1, data.addr).marginOnly(bottom: 156.sp)
            ]));
  }
}
